<template>
  <el-dialog :title="`${detail.id?'修改':'添加'}数据字典`" :visible.sync="dialogVisible">
    <el-form ref="detailForm" :model="detail" label-width="80px" size="small">
      <el-row>
        <el-col :span="24">
          <el-form-item prop="name" label="类型">
            <el-input v-model="detail.type" disabled/>
          </el-form-item>
          <el-form-item prop="name" label="名称">
            <el-input v-model="detail.name"/>
          </el-form-item>
          <el-form-item prop="name" label="编码">
            <el-input v-model="detail.code"/>
          </el-form-item>
          <el-form-item prop="name" label="描述">
            <el-input v-model="detail.remark"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="from-bnts">
        <el-button type="primary" :loading="loading" @click="submitData">保存</el-button>
        <el-button @click="dialogVisible=false">取消</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>

</template>
<script>
  import discretionApi from "@/api/system/discretion";

  export default {
    data() {
      return {
        loading: false,
        dialogVisible: false,
        detail: {},
      };
    },
    methods: {
      async initPage(detail) {
        this.dialogVisible = true;
        this.detail = detail || {};
      },
      submitData() {
        this.$refs["detailForm"].validate(async valid => {
          if (!valid) {
            return;
          }
          this.loading = true;
          let method = this.detail.id ? discretionApi.mod : discretionApi.add;
          await method(this.detail);
          this.loading = false;
          this.dialogVisible = false;
          this.$emit("submit");
        });
      },
    }
  };
</script>

